<?php

namespace app\weixin\model;
use think\Model;

class KnowledgeSubjectModel extends Model
{
    protected $name = 'knowledge_subject';
    /**
     * [getAllMenu 获取全部菜单]
     */
    public function getAllSubject()
    {
        return $this->order('id asc')->select();       
    }

    static public function subject($cate , $lefthtml = '— — ' , $pid=0 , $lvl=0, $leftpin=0 ){
        $arr=array();
        foreach ($cate as $v){
            if($v['parent_id']==$pid){
                $v['lvl']=$lvl + 1;
                $v['leftpin']=$leftpin + 0;//左边距
                $v['lefthtml']=str_repeat($lefthtml,$lvl);
                $arr[]=$v;
                $arr= array_merge($arr,self::subject($cate,$lefthtml,$v['id'],$lvl+1 , $leftpin+20));
            }
        }
        return $arr;
    }

}